import { Controller, UseGuards, Request, Get } from '@nestjs/common';
import { UsersService } from './users.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import {
  ApiTags,
  ApiOperation,
  ApiResponse as ApiSwaggerResponse,
} from '@nestjs/swagger';
import { UserVO } from './vo/user.vo';
import { ApiResponse } from '../../common/response';
import { ApiBearerAuth } from '@nestjs/swagger';

@ApiTags('用户')
@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @ApiOperation({ summary: '获取当前用户信息' })
  @ApiSwaggerResponse({
    status: 200,
    description: '获取成功',
    type: UserVO,
  })
  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Get('me')
  async getProfile(@Request() req): Promise<ApiResponse<UserVO>> {
    const result = await this.usersService.getProfile(req.user.id);
    return ApiResponse.success(new UserVO(result), '获取成功');
  }
}
